package com.whfc.iot.fse.crane.processor;

import com.alibaba.fastjson.JSONObject;
import com.whfc.common.constant.QueueConst;
import com.whfc.common.enums.DevicePlatform;
import com.whfc.common.util.JSONUtil;
import com.whfc.fse.dto.FseCraneRecordDTO;
import com.whfc.iot.fse.crane.entity.TwMsg;
import com.whfc.iot.fse.crane.entity.TwMsgWorkCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 塔吊消息处理-工作循环
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/7/17 9:17
 */
@Component
public class TwUpMsgProcessorWorkCycle implements TwUpMsgProcessor<TwMsgWorkCycle> {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Override
    public void processMsg(TwMsgWorkCycle twMsgWorkCycle) {
        String textMsg = JSONUtil.toString(twMsgWorkCycle);
        logger.info("处理塔吊工作循环命令:{}", textMsg);
        try {
            if (twMsgWorkCycle == null) {
                return;
            }
            FseCraneRecordDTO craneRecordDTO = new FseCraneRecordDTO();
            craneRecordDTO.setSn(twMsgWorkCycle.getDeviceSn()+"");
            craneRecordDTO.setPlatform(DevicePlatform.whfciot.name());

            craneRecordDTO.setStartTime(twMsgWorkCycle.getStartTime());
            craneRecordDTO.setEndTime(twMsgWorkCycle.getEndTime());

            craneRecordDTO.setStartHeight(twMsgWorkCycle.getStartHangHeight());
            craneRecordDTO.setEndHeight(twMsgWorkCycle.getEndHangHeight());

            craneRecordDTO.setStartRange(twMsgWorkCycle.getStartHangMargin());
            craneRecordDTO.setEndRange(twMsgWorkCycle.getEndHangMargin());

            craneRecordDTO.setMaxWeight(twMsgWorkCycle.getMaxWeight());
            amqpTemplate.convertAndSend(QueueConst.FSE_CRANE_RECORD_DATA, JSONUtil.toString(twMsgWorkCycle));
        } catch (Exception ex) {
            logger.error("", ex);
        }
    }
}
